<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('新增课程')"/>
    <th:block th:include="include :: select2-css"/>
</head>
<body>
<div class="main-content">
    <form id="form-user-add" class="form-horizontal">
        <input name="collegeId" type="hidden" id="treeId"/>
        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">课程名：</label>
                    <div class="col-sm-8">
                        <input name="courseName" placeholder="课程名" class="form-control" type="text" maxlength="30"
                               required>
                    </div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">开课学院：</label>
                    <div class="col-sm-8">
                        <div class="input-group">
                            <input name="deptName" onclick="deptRadioTree()" id="treeName" type="text"
                                   placeholder="请选择归属部门" class="form-control" required>
                            <span class="input-group-addon"><i class="fa fa-search"></i></span>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label">课程类型：</label>
                    <div class="col-sm-8">
                        <select name="courseType" class="form-control m-b"
                                th:with="dicts=${@sysDictDataServiceImpl.listDictDataByTypeSign('tiku_course_type')}">
                            <option th:each="dict : ${dicts}" th:text="${dict.dataKey}"
                                    th:value="${dict.dataValue}"></option>
                        </select>
                    </div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">课程编码：</label>
                    <div class="col-sm-8">
                        <input name="courseCode" placeholder="课程编码" class="form-control" type="text" maxlength="30"
                               required>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">学分：</label>
                    <div class="col-sm-8">
                        <input id="credit" name="credit" placeholder="学分" class="form-control" type="text"
                               maxlength="30" required>
                    </div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">任课老师：</label>
                    <div class="col-sm-8">
                        <input name="teacher" placeholder="任课老师" class="form-control" type="text">
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-3 control-label is-required">显示顺序：</label>
                    <div class="col-sm-8">
                        <input class="form-control" type="text" name="orderNum" id="orderNum" value="1" required>
                    </div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-3 control-label">使用状态：</label>
                    <div class="col-sm-8">
                        <div class="radio-box"
                             th:each="dict : ${@sysDictDataServiceImpl.listDictDataByTypeSign('sys_use_status')}">
                            <input type="radio" th:id="${dict.id}" name="use" th:value="${dict.dataValue}"
                                   th:checked="${dict.isDefault}">
                            <label th:for="${dict.id}" th:text="${dict.dataKey}"></label>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label class="col-xs-2 control-label">备注：</label>
                    <div class="col-xs-10">
                        <textarea name="remark" maxlength="500" class="form-control" rows="3"></textarea>
                    </div>
                </div>
            </div>
        </div>
    </form>
</div>

<th:block th:include="include :: footer"/>
<th:block th:include="include :: select2-js"/>
<script>
    const prefix = ctx + "center/course";


    function submitHandler() {
        if ($.validate.form()) {
            $.operate.save(prefix + "/add", $('#form-user-add').serialize());
        }
    }

    /*选择部门树 只显示到学院层次*/
    function deptRadioTree() {
        const options = {
            title: '学院选择',
            width: "380",
            url: prefix + "/collegeRadioTreeView",
            callBack: doSubmit
        };
        $.modal.openOptions(options);
    }

    function doSubmit(index, layero) {
        const tree = layero.find("iframe")[0].contentWindow.$._tree;
        if ($.tree.notAllowParents(tree)) {
            const body = layer.getChildFrame('body', index);
            $("#treeId").val(body.find('#treeId').val());
            $("#treeName").val(body.find('#treeName').val());
            layer.close(index);
        }
    }
</script>
</body>
</html>